#include "FileTest.h"
#include <stdio.h>
#include <string.h>

/*
 * Created: 2/24/12; CGP
 */

int main() {
    printf("Starting test...\n"); fflush(stdout);
    FileTest ft;
    const char *fileName = "test1";

    File *f1 = new File(fileName, "w");
    unsigned char data[] = "abcdefghijklmnopqrstuvwxyz";
    int dataLength = strlen((const char *) data)+1;
    int length = f1->Write(data, dataLength);
    if (! f1->Close()) {
        printf("ERROR: Could not close file\n");
    }
    delete f1;

    f1 = new File(fileName, "r");
    unsigned char buffer[100];
    length = f1->Read(buffer, dataLength);

    if (length != dataLength) {
        printf("ERROR: Could not read back all %d bytes of file\n", dataLength);
    }

    if (strcmp((const char *) data, (const char *) buffer) != 0) {
        printf("ERROR: Buffer (= %s) is not equal to data written (= %s)\n", buffer, data);
    }

    length = f1->Read(buffer, 1);
    if (length != 0) {
        printf("ERROR: End of file not correctly reached\n");
    }

    if (! f1->Close()) {
        printf("ERROR: Could not close file\n");
    }
    delete f1;
}




